package djl;

import static org.junit.Assert.assertTrue;
import djl.test.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IBulletSnapshot;
import robocode.control.snapshot.ITurnSnapshot;

/**
 * Illustrates JUnit testing of Robocode robots. This test verifies DaBeast's firing power.
 * 
 * @author David Joel Lazaro
 * 
 */
public class TestDaBeastBulletPower extends RobotTestBed {
  ITurnSnapshot lastTurnSnapshot;
  boolean bulletPower = false;

  /**
   * Specifies that SittingDuck and DaBeast are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,djl.DaBeast";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * Checks to see if DaBeast's firing power is within the proper range.
   * 
   * @param event Details about the completed turn.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    int power = 0;
    lastTurnSnapshot = event.getTurnSnapshot();

    for (IBulletSnapshot damage : lastTurnSnapshot.getBullets()) {
      // Gets the bullet's firing power
      power = (int) damage.getPower();
      // System.out.println(power);
    }

    if (power >= 3) {
      bulletPower = true;
    }

  }

  /**
   * The actual test, which asserts that DaBeast used a firing power within range.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check Damage", bulletPower);
  }
}
